package com.kanq.handler;

import com.kanq.common.utils.HanlpUtils;
import com.kanq.pojo.context.ChatContext;
import com.kanq.pojo.entity.KanqAiFileChunk;
import com.kanq.service.KanqAiFileChunkService;

import java.util.List;
import java.util.stream.Collectors;

public class KeywordSearchHandler implements ChatHandler {
    private final KanqAiFileChunkService fileChunkService;

    public KeywordSearchHandler(KanqAiFileChunkService fileChunkService) {
        this.fileChunkService = fileChunkService;
    }

    @Override
    public void handle(ChatContext context) {
        List<String> keywords = HanlpUtils.hanLPSegment(context.getRequest().getQuestion());
        List<Long> chunkIds = fileChunkService.fullTextSearch(keywords)
                .stream()
                .map(KanqAiFileChunk::getId)
                .collect(Collectors.toList());

        context.setChunkIds(chunkIds);
    }
}